<?php

namespace App\Http\Models;

class GoodsCoupon extends BaseModel
{
    protected $table = 'goods_coupon';
    protected $guarded = [];

    //对应商品表
    public function goods()
    {
        return $this->belongsTo(Goods::class, 'gid');
    }

    public static function getGoodsCouponlink($gid)
    {
        $model = self::select('couponlink', 'couponmoney')->where(['gid' => $gid])->first();
        return $model ? ['couponlink' => $model->couponlink, 'couponmoney' => $model->couponmoney] : ['couponlink' => '', 'couponmoney' => 0];
    }

    /**
     * 计算商品原价
     * @param $gid
     * @return int
     */
    public static function getGoodsOrigprice($gid)
    {
        $model = self::select('couponmoney')->where(['gid' => $gid])->first();
        return $model ? $model->couponmoney : 0;
    }
}